<template>
    <div style="width: 800px; margin: 50px auto 0;">
        <span style="display: inline-block; margin-bottom: 5px;">输入标题</span>
        <el-input
                type="text"
                autosize
                placeholder="请输入标题"
                v-model="textarea1"
        >
        </el-input>
        <div style="margin: 20px 0;"></div>
        <span style="display: inline-block; margin-bottom: 5px;">输入内容</span>
        <el-input
                type="textarea"
                :autosize="{ minRows: 10, maxRows: 18}"
                placeholder="请输入内容"
                v-model="textarea2"
        >
        </el-input>
        <div style="width: 800px; text-align: right; margin: 20px auto 50px;">
            <el-button @click="update" type="primary">提交<i class="el-icon-upload el-icon--right"></i></el-button>
        </div>

    </div>
</template>

<script>
    import {request} from "../../../network/request";

    export default {
        name: "write-forum",
        data() {
            return {
                textarea1: '',
                textarea2: ''
            }
        },
        methods:{
            update(){
                let userId = parseInt(sessionStorage.getItem("userId"));
                if(this.textarea1 != "" && this.textarea2 != "")
                    request({
                        url:"/insertDiscuss",
                        method: "post",
                        params:{
                            userId:userId,
                            name:this.textarea1,
                            des:this.textarea2,
                            imgUrl:sessionStorage.getItem("imgUrl")
                        }
                    }).then(res=>{
                        console.log(res.data);
                        this.$message({
                            message: '提交成功',
                            type: 'success'
                        });

                    }).catch(err=>{
                        //alert(err);
                        console.log(err);
                    });
                else{
                    this.$message.error("不能为空");
                }
                this.textarea1 = "";
                this.textarea2 = "";
            }
        }
    }
</script>

<style scoped>

</style>